package com.sky.controller.admin;

import com.sky.dto.EmployeeDTO;
import com.sky.dto.EmployeeLoginDTO;
import com.sky.dto.EmployeePageQueryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.EmployeeService;
import com.sky.vo.EmployeeLoginVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * 员工管理
 */
@RestController
@RequestMapping("/admin/employee")
@Slf4j
public class EmployeeController {
	
	private final EmployeeService employeeService;
	
	public EmployeeController(EmployeeService employeeService) {
		this.employeeService = employeeService;
	}
	
	/**
	 * 登录
	 */
	@PostMapping("/login")
	public Result<EmployeeLoginVO> login(@RequestBody EmployeeLoginDTO employeeLoginDTO) {
		log.info("员工登录：{}", employeeLoginDTO);
		return Result.success(employeeService.login(employeeLoginDTO));
	}
	
	/**
	 * 退出
	 */
	@PostMapping("/logout")
	public Result<String> logout() {
		return Result.success();
	}
	
	/**
	 * 分页查询
	 */
	@GetMapping("/page")
	public Result<PageResult> page(EmployeePageQueryDTO employeePageQueryDTO) {
		PageResult pageResult = employeeService.page(employeePageQueryDTO);
		return Result.success(pageResult);
	}
	
	/**
	 * 根据id查询
	 */
	@GetMapping("/{id}")
	public Result getEmpById(@PathVariable Long id) {
		return employeeService.getEmpById(id);
	}
	
	/**
	 * 新增员工
	 */
	@PostMapping
	public Result insert(@RequestBody EmployeeDTO employeeDTO) {
		return employeeService.insert(employeeDTO);
	}
	
	/**
	 * 更新员工
	 */
	@PutMapping
	public Result update(@RequestBody EmployeeDTO employeeDTO) {
		return employeeService.update(employeeDTO);
	}
	
	/**
	 * 修改员工账号活动状态
	 */
	@PostMapping("/status/{status}")
	public Result banEmp(@PathVariable Integer status, Long id) {
		return employeeService.banEmp(status, id);
	}
}
